home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol05 / 01 / isam / fig13.c next >
Text File  |  1989-12-11  |  2KB  |  73 lines

  1.  
  2.  
  3. /* WinTrieve C API, error codes are returned in global
  4. variable, iserrno. If an API function returns -1 it
  5. indicates an error. */
  6.  
  7. int     iserrno;
  8.  
  9. /* These values need to be available to other WinTrieve C
  10. API functions. For the example code given assume these
  11. variables are globally defined. This does not necessarily
  12. reflect the actual implementation. */
  13.  
  14. HWND    hWndServer;           /* server window handle */
  15. HWND    hWndClient;           /* client window handle */
  16. WORD    wmInitISAM;           /* WM_INITIATE_ISAM message
  17. value */
  18. WORD    wmSendISAM;           /* WM_SEND_ISAM message value
  19. */
  20. WORD    wmTermISAM;           /* WM_TERMINATE_ISAM message
  21. value */
  22.  
  23. /* Make connection to server. Argument hWnd is handle to a
  24. client window. Should ensure that hWnd remains valid
  25. throughout the life of the connection. */
  26.  
  27. int isconnect(
  28.     HWND    hWnd )
  29. {
  30.     static char    *szServerName = "ISAM SERVER";
  31.     static char    *szInit = "WM_INITIATE_ISAM";
  32.     static char    *szSend = "WM_SEND_ISAM";
  33.     static char    *szTerm = "WM_TERMINATE_ISAM";
  34.     static int     iFirstTime = 1;
  35.     long           lRetVal;
  36.  
  37.     /* Obtain WinTrieve protocol message values. */
  38.     if (iFirstTime) {
  39.         /* Only do this once. */
  40.         wmInitISAM = RegisterWindowMessage((LPSTR)szInit);
  41.         wmSendISAM = RegisterWindowMessage((LPSTR)szSend);
  42.         wmTermISAM = RegisterWindowMessage((LPSTR)szTerm);
  43.         iFirstTime = 0;
  44.     }
  45.  
  46.     /* Get the handle of the server's communications window.
  47. */
  48.     hWndServer = FindWindow((LPSTR)szServerName,
  49. (LPSTR)szServerName);
  50.     if (hWndServer == 0L) {
  51.         /* Error, server not running. */
  52.         iserrno = ISNOSERVER;
  53.         return -1;            /* Error, server not running.
  54. */
  55.     }
  56.  
  57.     lRetVal = SendMessage(hWndServer, WM_INITIATE_ISAM,
  58. hWnd, 0L);
  59.     if (lRetVal != ISOK) {
  60.         /* Error, two possible conditions, server must
  61.          * have died or maximum connections reached.
  62.          */
  63.         if (lRetVal == 0L)    /* Assign error code to
  64.             iserrno = ISNOSERVER;  / * global variable. */
  65.         else
  66.             iserrno = retVal;
  67.         return -1;            /* Indicates error. */
  68.     }
  69.     /* Connection successful. */
  70.     hWndClient = hWnd;
  71.     return 0;
  72. }
  73.